<?php

namespace Business;

class City extends Base {

	public function getCity() {
		return \Data\City::instance()->getCityAll();
	}

	public function getTowns($code) {
		return \Data\City::instance()->getTowns($code);
	}

	public function getCityInfoByCode($code) {
		if (!$code) {
			return array();
		}
		$townCode = 0;
		if ($code > 10000000000) {
			$cc = $code % 1000;
			$townCode = $code;
			$code = ($code - $cc) / 1000;
		}
		$codes = array();
		foreach (array(1000000, 1000, 0) as $k) {
			$y = $k ? $code % $k : 0;
			$codes[] = $code - $y;
		}
		$result = array();
		$cities = \Data\City::instance()->getCityByCodes($codes);
		foreach ($cities as $v) {
			$result[$v['Code']] = $v['Name'];
		}
		if ($townCode) {
			$town = \Data\City::instance()->getTownByCode($townCode);
			$result[$town['Code']] = $town['Name'];
		}
		return $result;
	}
}